package lapsnake.model.stmt;

import lapsnake.model.*;
import lapsnake.model.data.*;
import lapsnake.py.ast.ASTHelperFactory; 
import lapsnake.ui.JTreeLabel;

import java.awt.Component;
import java.beans.PropertyVetoException;

import org.python.antlr.ast.*;

/**Wrapper class with helper functions for If nodes*/
public class LapIf extends LapStatement {
	public final SingleChild<LapExpression> test = new SingleChild<>(this, LapExpression.class, true);
	@NewRow public final ChildList<LapStatement> body = new ChildList<>(this, LapStatement.class, false, true);
	@NewRow public final ChildList<LapStatement> orelse = new ChildList<>(this, LapStatement.class, true, true);

    public LapIf(PyAST pyAST, ChildField<? super LapIf> parent, If node) throws PropertyVetoException {
	super(pyAST, parent, node);
	
	ASTHelperFactory.makeHelper(pyAST, test, node.getInternalTest());
	ASTHelperFactory.makeHelpers(pyAST, body, node.getInternalBody());
	ASTHelperFactory.makeHelpers(pyAST, orelse, node.getInternalOrelse());
	
	
	buildTextNodes(node);
    }
    
    @Override
    protected Component getFillerComponent(int childIndex,
    	ChildField<?> childField)
    {
    	if(childField == test)
    		return new JTreeLabel("If", false);
    	else if(childField == body)
    		return new JTreeLabel("Then:", true);
    	else
    		return new JTreeLabel("Else:", true);
    }
}
